import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
// 需要左方向动画的路由用this.$router.to('****')
Router.prototype.togo = function (path) {
  this.isleft = true
  this.isright = false
  this.push(path)
}
// 需要右方向动画的路由用this.$router.goRight('****')
Router.prototype.goRight = function (path) {
  this.isright = true
  this.isleft = false
  this.push(path)
}
// 需要返回按钮动画的路由用this.$router.goBack()，返回上一个路由
Router.prototype.goBack = function () {
  this.isright = true
  this.isleft = false
  this.go(-1)
}
// 点击浏览器返回按钮执行，此时不需要路由回退
Router.prototype.togoback = function () {
  this.isright = true
  this.isleft = false
}
// 点击浏览器前进按钮执行
Router.prototype.togoin = function () {
  this.isright = false
  this.isleft = true
}
export default new Router({
  routes: [{
      path: '/',
      name: 'home',
      component: (resolve) => require(['@/pages/home'], resolve),
      redirect: '/home',
      children: [{
          path: '/home',
          name: 'home',
          component: (resolve) => require(['@/pages/home/home'], resolve),
          meta: {
            title: '推荐',
            keepAlive: false // 页面需要缓存
          }
        },
        {
          path: '/story',
          name: 'story',
          component: (resolve) => require(['@/pages/home/story'], resolve),
          meta: {
            title: '首页',
            keepAlive: false // 页面需要缓存
          }
        },
        {
          path: '/footprints',
          name: 'footprints',
          component: (resolve) => require(['@/pages/home/footprints'], resolve),
          meta: {
            title: '首页',
            keepAlive: false // 页面需要缓存
          }
        },
        {
          path: '/mine',
          name: 'mine',
          component: (resolve) => require(['@/pages/home/mine'], resolve),
          meta: {
            title: '我的',
            keepAlive: false // 页面需要缓存
          }
        },
      ]
    },
    {
      path: '/home/detail', //详情页面
      name: 'Detail',
      component: (resolve) => require(['@/pages/home/detail'], resolve),
      meta: {
        title: '详情'
      }
    },
    { //活动页面
      path: '/activity',
      name: 'activity',
      component: (resolve) => require(['@/pages/activity'], resolve),
      redirect: '/activity/bg',
      children: [{
          path: '/activity/bg',
          name: 'bg',
          component: (resolve) => require(['@/pages/activity/bg'], resolve),
          meta: {
            title: '阳光梦健康行 项目背景介绍'
          }
        },
        {
          path: '/activity/game',
          name: 'game',
          component: (resolve) => require(['@/pages/activity/game'], resolve),
          meta: {
            title: '阳光梦健康行 赛事详情'
          }
        }
      ]
    },
  ]
})
